<?php

namespace app\admin\model;

use think\Model;
use app\admin\model\ReceiveType;
use app\admin\model\ReceiveBuilding;
use app\admin\model\ReceiveFloor;
class ReceiveRoom extends Model
{

    

    

    // 表名
    protected $name = 'receive_room';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_id',
        'b_id',
        'f_id'
    ];

    public function getTypeIdAttr($value,$data)
    {
        $typeData = ReceiveType::where(['id'=>$data['receive_type_id']])->field("type_name")->find();
        return $typeData['type_name'];
    }
    public function getBIdAttr($value,$data)
    {
        $typeData = ReceiveBuilding::where(['id'=>$data['building_id']])->field("building_id")->find();
        return $typeData['building_id'];
    }
    public function getFIdAttr($value,$data)
    {
        $typeData = ReceiveFloor::where(['id'=>$data['floor_id']])->field("floor_no")->find();
        return $typeData['floor_no'];
    }
    public function receivefloor()
    {
        return $this->belongsTo('ReceiveFloor', 'floor_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
